package com.hzhr.iot.user.dao.helper;

import com.hzhr.iot.core.constant.CommonOptions;
import com.hzhr.iot.user.dao.UserDao;
import com.hzhr.iot.user.entity.UserEntity;
import com.hzhr.iot.user.queryModel.custom.UserCustomQueryModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class UserDaoHelper {
    @Autowired
    UserDao userDao;

    public UserEntity getById(int id) {
        UserCustomQueryModel userCustomQueryModel = new UserCustomQueryModel();
        userCustomQueryModel.setEqual_id(id);
        userCustomQueryModel.setEqual_isValid(CommonOptions.YES_NO.YES);
        userCustomQueryModel.setShow(true);
        UserEntity userEntity = userDao.selectEntity(userCustomQueryModel);
        return userEntity;
    }

    public int getCountByIdAndResourceCode(int id, String resourceCode) {
        if (resourceCode == null) return 0;
        UserCustomQueryModel userCustomQueryModel = new UserCustomQueryModel();
        userCustomQueryModel.setEqual_id(id);
        userCustomQueryModel.setLike_resourceCode(resourceCode + "%");
        userCustomQueryModel.setEqual_isValid(CommonOptions.YES_NO.YES);
        int count = userDao.selectCount(userCustomQueryModel);
        return count;
    }

    public UserEntity getByIdAndResourceCode(int id, String resourceCode) {
        if (resourceCode == null) return null;
        UserCustomQueryModel userCustomQueryModel = new UserCustomQueryModel();
        userCustomQueryModel.setEqual_id(id);
        userCustomQueryModel.setLike_resourceCode(resourceCode + "%");
        userCustomQueryModel.setEqual_isValid(CommonOptions.YES_NO.YES);
        userCustomQueryModel.setShow(true);
        UserEntity userEntity = userDao.selectEntity(userCustomQueryModel);
        return userEntity;
    }

    public int getCountByDeptId(int deptId) {
        UserCustomQueryModel userCustomQueryModel = new UserCustomQueryModel();
        userCustomQueryModel.setEqual_deptId(deptId);
        userCustomQueryModel.setEqual_isValid(CommonOptions.YES_NO.YES);
        int count = userDao.selectCount(userCustomQueryModel);
        return count;
    }
}
